﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MattDotson.GlobalToolkit
{
    /// <summary>
    /// Interface for exchange rate providers
    /// </summary>
    public interface ICurrencyExchangeRateProvider
    {
        /// <summary>
        /// Gets the exchange rate closest to, but before, the <paramref name="asOf"/> <see cref="DateTimeOffset"/>.
        /// </summary>
        /// <param name="fromCurrency">The ISO 4217 code for the currency to convert from</param>
        /// <param name="toCurrency">The ISO 4217 code for the currency to convert to</param>
        /// <param name="asOf">The date/time that the exchange rate was issued</param>
        /// <returns>An exchange rate to use for currency conversion</returns>
        ExchangeRate GetExchangeRateAsOf(string fromCurrency, string toCurrency, DateTimeOffset asOf);

        /// <summary>
        /// Gets the latest exchange rate available.
        /// </summary>
        /// <param name="fromCurrency">The ISO 4217 code for the currency to convert from</param>
        /// <param name="toCurrency">The ISO 4217 code for the currency to convert to</param>
        /// <returns>An exchange rate to use for currency conversion</returns>
        ExchangeRate GetLatestExchangeRate(string fromCurrency, string toCurrency);


        /// <summary>
        /// Gets all historical exchange rates.
        /// </summary>
        /// <param name="fromCurrency">The ISO 4217 code for the currency to convert from</param>
        /// <param name="toCurrency">The ISO 4217 code for the currency to convert to</param>
        /// <returns>A list of all available exchange rates.</returns>
        IEnumerable<ExchangeRate> GetAllExchangeRates(string fromCurrency, string toCurrency);

        /// <summary>
        /// Gets a value indicating whether this provider supports historical rates.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this provider supports historical rates; otherwise, <c>false</c>.
        /// </value>
        bool SupportsHistoricalRates { get; }
    }

    /// <summary>
    /// Represents an exchange rate between two currencies at a point in time.
    /// </summary>
    public class ExchangeRate
    {
        /// <summary>
        /// Gets or sets the ISO 4217 code for the currency to convert <b>from</b>.  This describes the direction of the <see cref="Rate"/>
        /// </summary>
        /// <value>From.</value>
        public string From { get; set; }

        /// <summary>
        /// Gets or sets the ISO 4217 code for the currency to convert <b>to</b>.  This describes the direction of the <see cref="Rate"/>
        /// </summary>
        /// <value>To.</value>
        public string To { get; set; }

        /// <summary>
        /// Gets or sets the rate.
        /// </summary>
        /// <value>The rate.</value>
        public double Rate { get; set; }

        /// <summary>
        /// Gets or sets the exact point in time this rate was issued.
        /// </summary>
        /// <value>As of.</value>
        public DateTimeOffset AsOf { get; set; }
    }
}
